#include "FuncTool.h"


NTSTATUS GetExportFunctionAddressByNameW(IN PCWSTR pName, OUT PVOID *pResultFunc) {
	UNICODE_STRING uniName = { 0 };
	RtlInitUnicodeString(&uniName, pName);
	if (uniName.Length > 0) {
		PVOID funcAddr = MmGetSystemRoutineAddress(&uniName);
		if (funcAddr) {
			*pResultFunc = funcAddr;
			return STATUS_SUCCESS;
		}
	}
	return STATUS_UNSUCCESSFUL;
}

NTSTATUS GetExportFunctionAddressByNameA(IN PCSTR pName, OUT PVOID *pResultFunc) {
	ANSI_STRING ansiStr = { 0 };
	RtlInitAnsiString(&ansiStr, pName);
	if (ansiStr.Length == 0) {
		return STATUS_UNSUCCESSFUL;
	}
	UNICODE_STRING uniStr = { 0 };
	RtlAnsiStringToUnicodeString(&uniStr, &ansiStr, TRUE);
	if (uniStr.Length == 0) {
		return STATUS_UNSUCCESSFUL;
	}
	NTSTATUS result = GetExportFunctionAddressByNameW(uniStr.Buffer, pResultFunc);
	return result;
}